package cn.tedu.boyou.mgrsite.controller;

import cn.tedu.boyou.acticle.domain.DestTheme;
import cn.tedu.boyou.acticle.service.IDestExtendService;
import cn.tedu.boyou.acticle.service.IDestThemeService;
import cn.tedu.boyou.acticle.service.IDestinationService;
import cn.tedu.boyou.common.query.DestThemeQuery;
import cn.tedu.boyou.common.query.DestinationExtendQuery;
import cn.tedu.boyou.common.query.DestinationQuery;
import cn.tedu.boyou.common.query.QueryObject;
import cn.tedu.boyou.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * 目的地
 */
@Controller
@RequestMapping("/destinationTheme")
public class DestinationThemeController {

    @Reference
    private IDestExtendService destExtendService;
    @Reference
    private IDestThemeService themeService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")DestThemeQuery qo){
        model.addAttribute("pageInfo",themeService.query(qo));
        List<DestTheme> toasts = themeService.getToasts(qo);
        model.addAttribute("toasts", toasts);
        if (toasts.size() > 0){
            model.addAttribute("parentTheme",toasts.get(toasts.size() - 1));
        }
        return "destinationTheme/list";
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public AjaxResult saveOrUpdate(DestTheme destTheme){
        themeService.saveOrUpdate(destTheme);
        return new AjaxResult();
    }
}
